public class CandidateCode {
	public static int student(String[] input1)
	{
		int[][] result = new int[input1.length][input1.length];
		for(int i = 0; i < input1.length; i++)
			result[i][i] = 1;
		for(int d = 1; d < input1.length; d++) {
			for(int i = 0, j = d; j < input1.length; i++, j++) {
				if(input1[i].charAt(0) == input1[j].charAt(0))
					result[i][j] = result[i + 1][j - 1] + 2;
				else
					result[i][j] = Math.max(result[i + 1][j] , result[i][j - 1]);
			}
		}
		return result[0][input1.length - 1];
	}
	public static void main(String[] args) {
		String[] input1 = {"Bharti", "Bharat", "Bhavya", "Brijesh", "Bhavna"};
		System.out.println(student(input1));
		String[] input2 = {"Bharti", "Bharat", "Chand", "Brijesh", "Bhavna"};
		System.out.println(student(input2));
		String[] input3 = {"Bharti", "Akash", "Bhavya", "Chand", "Brijesh", "Arvind", "Bhavna"};
		System.out.println(student(input3));
	}
}
